package com.devframe.web.util.user;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.devframe.sys.util.common.StringUtils;



public class UserInfo {

	/**
	 * userId
	 * 用户编号
	 */
	private String userId;

	/**
	 * userName
	 * 用户名称
	 */
	private String userName;

	/**
	 * 用户登录ip
	 * 
	 */
	private String loginIp;

	/**
	 * password
	 * 密码
	 */
	private String password;

	
	/**
	 * department
	 * 部门单位
	 */
	private String department;

	/**
	 * yhjz？警种
	 */
	private String yhjz;

	/**
	 * 用户登录机器名
	 */
	private String loginHost;

	/**
	 * 身份证号
	 */
	private String idCard;

	/**
	 * 警号
	 */
	private String policeId;

	/**
	 * 部门单位名称
	 */
	private String departmentName;
	
	/**
	 * isManager
	 * 是否管理员
	 */
	private boolean isManager;

	/**
	 * userProperties
	 * 用户属性
	 */
	private String userProperties = "";


    /** 用户所有权限代码集合，用于方便判断权限. */
    private Set powers = new HashSet();
    
    /** 
     * 用于有权限的菜单集合
     * rootMenus为根菜单列表
     * menuList为其他菜单列表
     **/
    private Map userMenu ;
    private List menuTreePowerlogic = new ArrayList();
    
    /** 用户角色数组. */
    private String[] userGroups;
    
    /** 登录次数*/
    private String logonNum;
    

	
	public String getUserProperties() {
		return userProperties;
	}

	public void setUserProperties(String userProperties) {
		this.userProperties = userProperties;
	}

	public Set getPowers() {
		return powers;
	}

	public void setPowers(Set powers) {
		this.powers = powers;
	}

	public List getMenuTreePowerlogic() {
		return menuTreePowerlogic;
	}

	public void setMenuTreePowerlogic(List menuTreePowerlogic) {
		this.menuTreePowerlogic = menuTreePowerlogic;
	}

	public String[] getUserGroups() {
		return userGroups;
	}

	public void setUserGroups(String[] userGroups) {
		this.userGroups = userGroups;
	}

	public UserInfo() {
	}

	public void setUserId(String userID) {
		this.userId = userID;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public void setPassword(String password) {
		this.password = password;
	}


	public void setDepartment(String department) {
		this.department = department;
	}

	public void setYhjz(String yhjz) {
		this.yhjz = yhjz;
	}


	public String getUserId() {
		return StringUtils.getNullByString(userId);
	}

	public String getUserName() {
		return StringUtils.getNullByString(userName);
	}

	public String getPassword() {
		return StringUtils.getNullByString(password);
	}

	public String getDepartment() {
		return StringUtils.getNullByString(department);
	}

	public String getYhjz() {
		return StringUtils.getNullByString(yhjz);
	}


	public String getDepartmentName() {
		return StringUtils.getNullByString(departmentName);
	}

	public void setDepartmentName(String departmentName) {
		this.departmentName = departmentName;
	}

	/**
	 * getUserPropertie
	 * 
	 * @param bmCode
	 *            String
	 * @return String
	 * @author Administrator
	 */
	public String getUserPropertie(String bmCode) {
		String value = "";
		if (StringUtils.isNotBlank(bmCode)) {
			int type = new Integer(bmCode).intValue();
			switch (type) {
			case 1:
				value = this.getUserName();
				break;
			case 2:
				value = this.getUserId();
				break;
			case 3:
				value = this.getPassword();
				break;
			case 4:
				value = this.getDepartment();
				break;
			case 5:
				value = this.getPoliceId();
				break;
			case 6:
				value = this.getIdCard();
				break;
			case 7:
				value = this.getDepartmentName();
				break;
			case 8:
				value = "";//this.getDepartmentBz();
				break;
			default:
				value = this.getUserId();
				break;
			}
		}
		if (StringUtils.isBlank(value)) {
			value = "";
		}
		return value.trim();
	}

	public String getPoliceId() {
		return StringUtils.getNullByString(policeId);
	}


	/**
	 * getUserPropertiesBySQL
	 * 
	 * @param userPropertie
	 *            String
	 * @return String
	 * @author Administrator
	 */
	public String getUserPropertiesBySQL(String userPropertie) {
		int index = userPropertie.indexOf('#');
		String key = userPropertie.substring(index + 1, index + 2);
		userProperties = userPropertie.replaceAll("#" + key, "'" + getUserPropertie(key) + "'");
		return userProperties;
	}

	/**
	 * getUserPropertiesByParam
	 * 
	 * @param userPropertie
	 *            String
	 * @return String
	 * @author Administrator
	 */
	public String getUserPropertiesByParam(String userPropertie) {
		int index = userPropertie.indexOf('#');
		String key = userPropertie.substring(index + 1, index + 2);
		userProperties = userPropertie.replaceAll("#" + key, getUserPropertie(key));
		return userProperties;
	}

	/**
	 * getNormalDeptCode
	 * 
	 * @param deptCode
	 *            String
	 * @return String
	 * @author Administrator
	 */
	private String getNormalDeptCode(String deptCode) {
		String dept = deptCode;
		if (StringUtils.isNotBlank(dept)) {
			dept = dept.trim();
			if (dept.substring(6).equals("000000")) {
				dept = dept.substring(6) + "%";
			} else if (!dept.substring(6).equals("000000") && dept.substring(8).equals("0000")) {
				dept = dept.substring(8) + "%";
			} else if (!dept.substring(8).equals("0000") && dept.substring(10).equals("00")) {
				dept = dept.substring(10) + "%";
			}
		}
		return dept;
	}
	/**
	 * 添加用户权限.
	 * @param powerTag 权限标识.
	 */
	public void addPower(String powerTag) {
		powers.add(powerTag);
	}
	/**
	 * 判断是否有权限
	 * @param powerTag 权限代码
	 * @return boolean
	 * 
	 */
	public boolean hasPower(String powerTag){
		if(this.isManager){
			return true;
		}
		return powers.contains(powerTag);
	}

    public String getIdCard() {
        return idCard;
    }

    public void setIdCard(String idCard) {
        this.idCard = idCard;
    }

    public void setPoliceId(String policeId) {
        this.policeId = policeId;
    }

    public String getLoginIp() {
        return loginIp;
    }

    public void setLoginIp(String loginIp) {
        this.loginIp = loginIp;
    }

    public String getLoginHost() {
        return loginHost;
    }

    public void setLoginHost(String logonHost) {
        this.loginHost = logonHost;
    }

    public boolean getIsManager() {
        return isManager;
    }

    public void setIsManager(boolean isManager) {
        this.isManager = isManager;
    }

    public Map getUserMenu() {
        return userMenu;
    }

    public void setUserMenu(Map userMenu) {
        this.userMenu = userMenu;
    }

	/**
	 * @return the logonNum
	 */
	public String getLogonNum() {
		return logonNum;
	}

	/**
	 * @param logonNum the logonNum to set
	 */
	public void setLogonNum(String logonNum) {
		this.logonNum = logonNum;
	}
}
